/*
 * @FileName: [PaginationList.java] 
 * @Package com.bcinfo.upp.util 
 * 
 * 
 * Copyright (c) 2011-2015 BCINFO Technology Limited Com.
 * All rights reserved.
 * 
 * This software is the confidential and proprietary 
 * information of BCINFO Technology Limited Company
 * ("Confidential Information"). You shall not disclose 
 * such Confidential Information and shall use it only
 * in accordance with the terms of the contract agreement 
 * you entered into with RKY.
 * 
 * $Rev: 17 $
 * $LastChangedDate: 2013-11-25 11:41:03 +0800 (Mon, 25 Nov 2013) $
 * $LastChangedBy: huangb $
 * 
 * @category bcinfo-upp
 * @version 1.1
 * @author $Author: huangb $
 *
 * Change History:[Formatter: author date description] <br/>
 * 1
 * 2
 * 3
*/


package com.bci.pwtz.common.util;

import java.io.Serializable;
import java.util.List;

/**
 * 分页工具类 <br/>
 * <p>Description:<br/>
 *    <p>封装分页功能，包括当前页、总页数、总条数、记录列表
 *
 * <p>For Examples <br/>
 * <PRE>
 *      
 * </PRE>
 * <p>
 */
public class PaginationList<T> implements Serializable
{
    /**  
     * @Fields serialVersionUID : 序列化UID 
     */
    private static final long serialVersionUID = -8343671472906543580L;
    /**  
     * @Fields currPage : 当前页码 
     */
    private int currPage;
    /**  
     * @Fields totalPage :总页数  
     */
    private int totalPage;
    /**  
     * @Fields pageSize :每页记录数 
     */
    private int pageSize;
    /**  
     * @Fields totalRecord :总记录数  
     */
    private int totalRecord;
    /**
     * @Fields records :当前页记录列表
     */
    private List<T> records;
    
    public int getCurrPage()
    {
        if (currPage <= 0 || currPage > getTotalPage())
        {
            if (currPage <= 0)
            {
                currPage = 1;
            } else
            {
                currPage = getTotalPage();
            }
        }
        return currPage;
    }
    public void setCurrPage(int currPage)
    {
        this.currPage = currPage;
        
    }
    public int getTotalPage()
    {
        totalPage=totalRecord % getPageSize() == 0 ? (totalRecord / getPageSize()) : ((totalRecord / getPageSize()) + 1);
        return totalPage;
    }
    public void setTotalPage(int totalPage)
    {
        this.totalPage = totalPage;
    }
    public int getPageSize()
    {
        return (pageSize<=0?5:pageSize);
    }
    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }
    public int getTotalRecord()
    {
        return totalRecord;
    }
    public void setTotalRecord(int totalRecord)
    {
        this.totalRecord = totalRecord;
    }
    public List<T> getRecords()
    {
        return records;
    }
    public void setRecords(List<T> records)
    {
        this.records = records;
    }
    
    public int getStartIndex(){
        return (this.currPage-1)*getPageSize();
    }
    public int getEndIndex(){
        return (this.currPage*getPageSize());
    }
    
}
